<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script src="./data.js"></script>
<script>
    function findPerson(personTree) {
        return personTree.drillPersonInfos.find(v => v);
    }

    function hasRooter ({ drillRoleCode, drillRole } = {}) {
        return drillRoleCode === '1720262536462589954' || drillRole === '总指挥'
    }

    function hasGrouper ({ drillRoleCode, drillRole } = {}) {
        return drillRoleCode === '7cd6254d-6e66-45a6-ab61-de17eebff425' || drillRole === '组长'
    }

    function findRooter(personTree) {
        return personTree.drillPersonInfos.find(hasRooter)
    }
    function findGrouper(personTree) {
        return personTree.drillPersonInfos.find(hasGrouper)
    }
    function findDrillRoot(personTree, findRole) {
        let role;
        if (Array.isArray(personTree)) {
            role = personTree.find(person => findDrillRoot(person, findRole))
            if (role) return role;
        }

        if (personTree?.drillPersonInfos?.length) {
            role = findRole(personTree);
            if (role) return role;
        }

        if (personTree?.drillPersonInfoDictTreeNodes?.length) {
            role = findDrillRoot(personTree.drillPersonInfoDictTreeNodes, findRole)
            if (role) return role;
        }
    }

    console.log(findDrillRoot(data, (tree) => {
        if (tree.dictCode !== 'emergency_drill_headquarters') {
            const grouper = findGrouper(tree)
            console.log(tree, grouper)
            /**
             * 1. 如果这个组不存在 组长
             * 2. 并且这个组，不是 总指挥
             */
            if (!grouper) {
                return true;
            }
        }
    }))
</script>
</body>
</html>